package video.com.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.Map;
import java.util.Set;

import lombok.*;

/**
 * <p>
 * 
 * </p>
 *
 * @author xwj
 * @since 2024-03-11
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class UserBehavior implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    private String keyId;

    private String userId;

    private boolean agree;

    private boolean disagree;

    private boolean collection;

    private boolean coin;

    private boolean comment;

    private boolean forward;

    private boolean watch;

    private Date behaviorTime;

    /**
     * 用户记录的类型 0：评论 1： 视频
     */
    private int behaviorType;

    public void setAgree(Object agree) {

        if(agree instanceof Boolean){
            this.agree = (boolean)agree;
        }else if(agree instanceof Integer){
            this.agree = (int) agree > 0 ;
        }


    }

    public void setDisagree(Object disagree) {

        if(disagree instanceof Boolean){
            this.disagree = (boolean)disagree;
        }else if(disagree instanceof Integer){
            this.disagree = (int) disagree > 0 ;
        }
    }

    public void setCollection(Object collection) {

        if(collection instanceof Boolean){
            this.collection = (boolean)collection;
        }else if(collection instanceof Integer){
            this.collection = (int) collection > 0 ;
        }
    }

    public void setCoin(Object coin) {

        if(coin instanceof Boolean){
            this.coin = (boolean)coin;
        }else if(coin instanceof Integer){
            this.coin = (int) coin > 0 ;
        }
    }

    public void setComment(Object comment) {

        if(comment instanceof Boolean){
            this.comment = (boolean)comment;
        }else if(comment instanceof Integer){
            this.comment = (int) comment > 0 ;
        }
    }

    public void setForward(Object forward) {

        if(forward instanceof Boolean){
            this.forward = (boolean)forward;
        }else if(forward instanceof Integer){
            this.forward = (int) forward > 0 ;
        }
    }

    public void setWatch(Object watch) {

        if(watch instanceof Boolean){
            this.watch = (boolean)watch;
        }else if(watch instanceof Integer){
            this.watch = (int) watch > 0 ;
        }
    }

    public void setField(Map<String, Object> map) {
        try{
            Set<Map.Entry<String, Object>> entries = map.entrySet();

            for(Map.Entry<String, Object> entry : entries){

                if(entry.getValue() == null){
                    continue;
                }

                switch (entry.getKey()){
                    case "keyId":
                        this.setKeyId(entry.getValue().toString());
                        break;
                    case "userId":
                        this.setUserId(entry.getValue().toString());
                        break;
                    case "agree":
                        this.setAgree(entry.getValue());
                        break;
                    case "disagree":
                        this.setDisagree(entry.getValue());
                        break;
                    case "coin":
                        this.setCoin(entry.getValue());
                        break;
                    case "collection":
                        this.setCollection(entry.getValue());
                        break;
                    case "forward":
                        this.setForward(entry.getValue());
                        break;
                    case "comment":
                        this.setComment(entry.getValue());
                        break;
                    case "watch":
                        this.setWatch(entry.getValue());
                        break;
                    default:
                        break;
                }
            }
        }catch (Exception e){

        }

    }
}
